# -*- coding: utf-8 -*-
import KBEngine
from KBEDebug import *
import time
import d_mail

class Mail:
    def __init__(self):
        pass

    # 对自己进行一次动态操作
    def mailOptMTM(self, disasterId, itemId, changeScore, curTime):
        mail_info = {
            "interact_type": d_mail.mails["interact_type_mtm"]["value"],
            "opt_type": d_mail.mails["opt_type_%d" % (disasterId)]["value"],
            "other_name": self.nickName,
            "item_id": itemId,
            "change_score": changeScore,
            "opt_time": curTime
        }
        self.mail_info_list.insert(0,mail_info)
        if len(mail_info_list) > 50:
            self.mail_info_list.pop()
        self.mail_info_list = self.mail_info_list

    # 别人对自己进行一次动态操作
    def mailOptOTM(self, disasterId, otherName, itemId, changeScore, curTime):
        print("mailOptOTM ==>> disasterId : ", disasterId, ", changeScore : ", changeScore, ", curTime : ", curTime)
        mail_info = {
            "interact_type": d_mail.mails["interact_type_otm"]["value"],
            "opt_type": d_mail.mails["opt_type_%d" % (disasterId)]["value"],
            "other_name": otherName,
            "item_id": itemId,
            "change_score": changeScore,
            "opt_time": curTime
        }
        self.mail_info_list.insert(0, mail_info)
        if len(self.mail_info_list) > 50:
            self.mail_info_list.pop()
        self.mail_info_list = self.mail_info_list
        # accountRef.mailOptMTO(self, disasterId, self.nickName, itemId, changeScore, curTime)

    # 自己对别人进行一次动态操作,需要调用其他实体
    def mailOptMTO(self, accountRef, disasterId, otherName, itemId, changeScore, curTime):
        print("mailOptMTO ==>> nickName : ", nickName, ", disasterId : ", disasterId,
              ", changeScore : ", changeScore, ", curTime : ", curTime)
        mail_info = {
            "interact_type": d_mail.mails["interact_type_mto"]["value"],
            "opt_type": d_mail.mails["opt_type_%d" % (disasterId)]["value"],
            "other_name": otherName,
            "item_id": itemId,
            "change_score": changeScore,
            "opt_time": curTime
        }
        self.mail_info_list.insert(0, mail_info)
        if len(self.mail_info_list) > 50:
            self.mail_info_list.pop()
        self.mail_info_list = self.mail_info_list
        accountRef.mailCallOTM(optType, self.nickName, itemId, changeScore, curTime)

    def mailLook(self):
        self.mail_look_time = int(time.time())